#ifndef SRDATABASE_H
#define SRDATABASE_H

#include <QObject>
#include <QSqlDatabase>


class SRDatabase : public QObject
{
    Q_OBJECT
public:

    struct stLogInfo {
        QString id;
        QString info;
        QString name;
        QString time;
    };

    struct stXlsRecord {
        QString id;
        QString sigDataHex;
        QString sigData;
        QString auditId;
        QString name;
        QString crtTime;
        int isExport;
        stXlsRecord(const QString& _sigDataHex = "",
                    const QString& _auditId = "",
                    const QString& _sigData = "",
                    const QString& _name = "")
            :sigDataHex(_sigDataHex), sigData(_sigData),
              auditId(_auditId),name(_name){ }
    };

    static SRDatabase* DB(void);

    int open(QString _userName);

    int close(void);

    int writeOperateLog(QString _doWhat, int _type = 1);

    int getOperateLog(int b, int e,
                      QList<stLogInfo>& _listLog);

    int getOperateLogSize(void);


    int upXlsRecordExport(const QString& auditId,
                          int isExport = 1);

    int writeXlsRecord(const stXlsRecord& _record,
                       int _type = 0);

    int getXlsTimeRecord(QString btime, QString etime,
                      QList<stXlsRecord>& _listXls);

    int getXlsRecord(int b, int e,
                      QList<stXlsRecord>& _listXls);
    int getXlsRecordSize(void);

    // 检查是否有这个审核编号
    // 0 有  非0 无
    int checkXlsRecord(const QString& _auditId);




public:

    // ture : 存在 false : 不存在
    static bool isExist(void);

    // 注册初始化数据库
    static int registerDB(void);

    static void DBPath(QString& path);

private:

    explicit SRDatabase(QObject *parent = 0);
    ~SRDatabase(void);

    static QString encryptionPswd(const QString& _pswd);

signals:

public slots:


private:
    QSqlDatabase sqlDatabase_;
    static QString strFilename_;
    static SRDatabase dbInstance_;

private:

    QString userName_;

};

#endif // SRDATABASE_H
